<?php

namespace app\admin\controller\other;

use app\common\controller\AdminController;
use app\common\service\RedisService;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;

/**
 * @ControllerAnnotation(title="其他的额外配置")
 */
class Config extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\OtherConfig();
        
    }

    

    // 分别同步各项配置:
    public function sync(){
        $list = $this->model->select();
        foreach($list as &$item){
            switch ($item->id ){
                case 1:
                    //上架手续费率
                    // redis.Client3.set(`${KEYS.RATE_HANHDING}`, rate.toString());
                    RedisService::select(3)->set(self::KEYS['RATE_HANHDING'], $item->value3 .'' );
                    break;
                case 2:
                    //直接推荐人分成比例
                    break;
                case 3:
                    // 间接推荐人分成比例
                    break;
                case 4:
                    //新用户特权
                    break;
                case 5:
                    // 统一抢购数量限制
                    RedisService::select(2)->set(self::KEYS['USER_COMMON_LIMIT'], intval($item->value1) );
                break;
                case 6:
                    // 委托上架时间
                    // await redis.Client3.set(`${KEYS.GOODS_LAUNCH_TIME}`, time.toString());
                    RedisService::select(3)->set(self::KEYS['GOODS_LAUNCH_TIME'], $item->value1 . '' );
                    break;
                case 7:
                    //全平台上架状态
                    // redis.Client3.set(`${KEYS.ALL_GOODS_LAUNCH_STATE}`, state.toString());
                    RedisService::select(3)->set(self::KEYS['ALL_GOODS_LAUNCH_STATE'], $item->value1 . '' );
                    break;
                case 8:
                    //上架商品涨幅
                    // redis.Client3.set(`${KEYS.GOODS_LAUNCH_GAIN}`, rate.toString());
                    RedisService::select(3)->set(self::KEYS['GOODS_LAUNCH_GAIN'], $item->value2 . '' );
                    break;
                default:
                    break;
            }
        }
        $this->success("设置生效");
    }

}